package httpHandler

import (
	baseHttp "gitee.com/zaiqiang231/go-base-app/base_app/http"
	"gitee.com/zaiqiang231/zcamp-service-camp/app/http/service"
	"gitee.com/zaiqiang231/zcamp-service-camp/app/model/req"
	"github.com/gin-gonic/gin"
	"net/http"
)

func CreateProduct(c *gin.Context) {
	var request req.ProductCreateReq
	if err := c.ShouldBindJSON(&request); err != nil {
		baseHttp.WriteResponse(c, http.StatusBadRequest, err.Error(), nil)
		return
	}
	err := service.ServiceProductInstance.CreateProduct(c, request)
	if err != nil {
		baseHttp.WriteResponse(c, http.StatusInternalServerError, err.Error(), nil)
		return
	}
	baseHttp.WriteResponse(c, 0, "success", gin.H{})
}

func ProductListForCamp(c *gin.Context) {
	var request req.ProductListForCampReq
	if err := c.ShouldBindQuery(&request); err != nil {
		baseHttp.WriteResponse(c, http.StatusBadRequest, err.Error(), nil)
		return
	}
	list, _, err := service.ServiceProductInstance.ProductListForCamp(c, request)
	if err != nil {
		baseHttp.WriteResponse(c, http.StatusInternalServerError, err.Error(), nil)
		return
	}
	baseHttp.WriteResponse(c, 0, "success", gin.H{
		"list":     list,
		"show_num": 8,
	})
}
